package com.xckj.zuoliao.ui.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;

import androidx.annotation.NonNull;

import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;
import com.tencent.bugly.crashreport.CrashReport;
import com.xckj.zuoliao.R;
import com.xckj.zuoliao.databinding.ActivitySplashBinding;
import com.xckj.zuoliao.framework.BaseActivity;
import com.xckj.zuoliao.global.Constant;
import com.xckj.zuoliao.utils.SpUtil;

/**
 * @Author: 代码的搬运工
 * @Describe: 启动页
 * @Date: 2024/3/27 22:03
 */
@SuppressLint("CustomSplashScreen")
public class SplashActivity extends BaseActivity<ActivitySplashBinding> {
    @Override
    protected boolean isFitsSystemWindows() {
        return false;
    }

    @Override
    protected int loadLayout() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initData() {
        CrashReport.initCrashReport(this, Constant.BUGLY_APP_ID, false);
        int time = 2000;
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (TextUtils.isEmpty(SpUtil.getString(getApplicationContext(), Constant.ID))) {
                    startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                    finish();
                } else {
                    startActivity(new Intent(SplashActivity.this, HomeActivity.class));
                    finish();
                }
            }
        }, time);
    }

    @Override
    protected void setListener() {

    }

    @NonNull
    @Override
    protected ImmersionBar createStatusBarConfig() {
        return super.createStatusBarConfig().hideBar(BarHide.FLAG_HIDE_BAR);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
